﻿using System;
using System.IO;
using System.Text.RegularExpressions;

namespace TLang
{
    class Program
    {
        static void Main(string[] args)
        {
            TextReader reader = Console.In;
            string allText = reader.ReadToEnd();

            string[] lines = allText.Split('\n');

            Regex operation = new Regex("\\^[=#@]( [\\-]?[0-9]*)*\\$", RegexOptions.Multiline);

            foreach (string line in lines)
            {
                string tmp = line;
                Match m = operation.Match(tmp);

                while (m.Captures.Count > 0)
                {
                    Int64 result = OperationResult(m.Captures[0].Value);
                    tmp = operation.Replace(tmp, result.ToString(), 1);

                    m = operation.Match(tmp);
                }

                Console.WriteLine(tmp);
            }
        }

        private static Int64 OperationResult(string operation)
        {
            operation = operation.Replace("^", string.Empty);
            operation = operation.Replace("$", string.Empty);
            string[] parts = operation.Split(' ');
            Int64 operand1 = 0;
            Int64 operand2 = 0;

            if (parts.Length > 1)
            {
                if (!Int64.TryParse(parts[1], out operand1))
                {
                    return 0;
                }
            }

            if (parts.Length > 2)
            {
                if (!Int64.TryParse(parts[2], out operand2))
                {
                    return 0;
                }
            }

            switch (parts[0])
            {
                case "=":
                    return operand1 + operand2;
                case "#":
                    return operand1 * operand2;
                case "@":
                    if (operand2 == 0)
                        return -operand1;
                    return operand1 - operand2;
                default:
                    return 0;
            }

            return 0;
        }
    }
}
